<?php
namespace Admin\Controller;
use Think\Controller;
class AdminclubController extends Controller {

     /*1.设置状态*/
    public function Aclublist(){
       $data['club_id']=$_SESSION['club_id'];
       // var_dump($data);
       $clubsmodel=M('club_info');  
       $club_info=$clubsmodel->where($data)->select();
       $this->club_info=$club_info;
       $this->display();
    }
     /*2.设置状态*/
  public function detailclub($club_id){
        $clubsmodel=M('club_info');
        $club=$clubsmodel->select($club_id); 
        $this->club=$club;
        $this->display();
    }


    /*3.设置状态*/

  public function state(){
        $club_id=I('club_id');
        $club_info= M('club_info');
        // 要修改的数据对象属性赋值
        $data['state'] = 1;
        if($club_info->where("club_id=$club_id")->save($data)) {
            $this->success('设置禁用成功');
        }else{
            $this->error('设置禁用失败');
        }
    }
    //取消禁用
    public function restate(){
        $club_id=I('club_id');
        $club_info= M('club_info');
        // 要修改的数据对象属性赋值
        $data['state'] = 0;
        if($club_info->where("club_id=$club_id")->save($data)) {
            $this->success('取消禁用成功');
        }else{
            $this->error('取消禁用失败');
        }
    }

    public function editclub(){
        $club_id=$_GET['club_id'];
        $clubsmodel=M('club_info');//表明,conf中定义前缀
        $club = $clubsmodel->where("club_id=$club_id")->select();
        $this->club=$club;//name属性对应的值 $this->对应值=$find;
        $this->display();
    }
    public function updateclub(){
            $data=$_POST;
            $file=$_FILES;
            //dump($file);
            $club_id=$data['club_id'];
            //dump($id);        
            $clubsmodel = M('club'); // 实例化User模型
            // 要修改的数据对象属性赋值
            //$userModel->create();   // 根据表单提交的POST数据创建数据对象
            //dump($data);
        //$result=$userModel->where("id=$id")->save($data);

        if ($file['c_pic']['size']==0) {
            //没有修改头像
            $result=$clubsmodel->where("club_id=$club_id")->save($data);
  
        }else{
            //修改头像
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize  = 3145728 ;// 设置附件上传大小
            $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =  './';
            $upload->savePath =  'Public/Admin/clubphoto/';// 设置附件上传目录
            $upload->autoSub = false;
            $upload->saveName = date("YmdHis").rand(100,999);//定义名字
            $info = $upload->upload();
    
            if(!$info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
             }else{// 上传成功 获取上传文件信息
                 //保存表单数据 包括附件数据
                $data['c_pic']= $info['c_pic']['savename']; 
                $result=$clubsmodel->where("club_id=$club_id")->save($data);
                    if ($data['oldpic']!='nopic.jpg') {
                    $oldpicPath='Public/Admin/clubphoto/'.$data['oldpic'];
                    unlink($oldpicPath);
                        }
                    }
            }
        if($result){
             $this->success('修改成功！','../Cclub/cclublist');
             }
            else{
                $this->error('修改失败！');
                }
    }
    
   //   public function doregclub(){ 
   //      $club=D("club");

   //      if ($club->create()) {
          
   //          if ($_FILES['file']['error'] == 0) {
   //              $logoinfo = $this->upload();
   //              $pname = $logoinfo['file']['savename'];
   //          } else {
   //              $pname = "default.jpg";
   //          }
   //          $club->c_phone=trim(I('post.c_phone'));
   //          $club->c_name=trim(I('post.c_name'));
   //          $club->club_id=trim(I('post.club_id'));
   //          $club->c_address=trim(I('post.c_address'));
   //          $club->c_time=trim(I('post.c_time'));
   //          $club->c_info=trim(I('post.c_info'));
   //          $club->c_introduce=trim(I('post.c_introduce'));
   //          $club->c_pic=$pname;
   //          if (false !== $club->add()) {
   //              $this->success('注册成功！', U('CIndex/reg'));
   //          } else {         $this->error('数据错误');           }
   //      } else {
   //          $this->error($club->getError());
   //      }
   //  }
   //  public function upload()
   //  {
   //      $upload = new \Think\Upload();// 实例化上传类
   //      $upload->maxSize = 3145728;// 设置附件上传大小
   //      $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
   //      $upload->rootPath = './Public/Admin/clubphoto/'; // 设置附件上传根目录
   //      //$upload->savePath  =     ''; // 设置附件上传（子）目录
   //      $upload->autoSub = false;
   //      $info = $upload->upload();  // 上传文件
       
   //      if (!$info) {
   //          $this->error($upload->getError());
   //      } else {
   //          //$this->success('上传成功！');
   //          return $info;
   //      }
   //  }
   //  function checkTele(){
   //  $c=$_GET["tt"];//I('get.tt')
   //  $rs=M('club')->where("c_phone='$c'")->select();
   //  if($rs)
   //      echo "手机号已注册";
   //  else echo "手机号可用";
   // }
    
}